******************************************************************************
******************************************************************************
*****************This produces tables & figures for the paper*****************
******************************************************************************
******************************************************************************

capture log close
capture clear all
 set matsize 10000
 
cd "C:\Users\jenny\Documents\Documents\Don Weatherburn\home detention\version 6\R&R\R&R2\Programs"
log using Analysis.log, replace

use EM.dta, clear
  sort judge_code

*****************************************************************************
*********Figure 1**********************************************************
*****************************************************************************

   gen judge_hd_proc=hd_mean+resid_hd
   gen judge_SL_proc=SL_mean+resid_SL

   sum judge_hd_proc if indexapr_flag=="Yes" , detail
   gen  judge_hd_5s=r(p5)
   gen judge_hd_95s=r(p95)
   gen judge_hd90s=judge_hd_proc>judge_hd_5s & judge_hd_proc<judge_hd_95s

 ***graphing judge tendency
 histogram judge_hd_proc if judge_hd90s==1 & indexapr_flag=="Yes", fraction bin(100) xtitle(Judge Tendency to Refer to EM Assessment) xmtick(##5, labels valuelabel)
 graph save "Figure_1" , asis replace

*****************************************************************************
*********Table 2**********************************************************
*****************************************************************************
**Full Sample
  tab jcrime_type 
  bysort punish: tab jcrime_type 

**Estimation Sample
  tab jcrime_type if indexapr_flag =="Yes"
  bysort punish: tab jcrime_type if indexapr_flag =="Yes"

  tab jcrime_type  if indexapr_flag =="Yes"
  bysort punish: tab jcrime_type if indexapr_flag =="Yes"


   
   ****************************************************************************
  * ****************Table 1:  assignment of case to judge is as good as random**
  ******************************************************************************
  use EM_Reoff.dta,clear
   
  global controlsx " nprior5_courtj nolegrep i.lga  "
. global controlsa " age age2 gender injury neg_driving break_enter theft fraud pub_order traffic"
  global controlsb "i.courtid#i.year"

   **served EM
  regress jindex_hd_old  $controlsa $controlsx $controlsb if indexapr_flag=="Yes" & year<2008 ,  vce(cluster CourtLocationID )
   outreg2 using "Table1.xls", sortvar(jindex_hd jindex_ss index_ppenval i.jcrime_type age gender $controlsx ) ctitle(served hd) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)   excel  label dec(4)
   testparm  age age2 gender injury neg_driving break_enter theft fraud pub_order traffic nprior5_courtj nolegrep
  
  ****judge tendency for EM referrals
  regress judge_hd_proc  $controlsa $controlsx $controlsb if indexapr_flag=="Yes" & year<2008  ,  cluster(CourtLocationID)
  testparm  age age2 gender injury neg_driving break_enter theft fraud pub_order traffic nprior5_courtj nolegrep
  outreg2 using "Table1.xls", sortvar(jindex_hd jindex_ss index_ppenval i.jcrime_type age gender $controlsx ) ctitle(judge_hd_proc) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)   excel  label dec(4)

  
  ********************generate outcomes (every 6 mnths)
  
	use EM_Reoff.dta, clear
	local N=20 
	
	gen  reoffa=0
	gen  reoff0month=0
		forvalues x=1/`N' {
		gen cc`x'=(cen<`x'*366/2)
      gen dd`x'=(died<`x'*366/2)
	  gen died`x' =(dd`x'==1)
	  replace died`x'=0 if dod==.
      gen cen`x' =(cc`x'==1)
	gen  reoff`x'month=((reoffa+reoff`x')>=1)
	replace reoff`x'month=. if reoffa==.
	replace  reoff`x'month=. if reoff`x'month==0  & (died`x'==1|cen`x'==1)
	replace  numberoff`x'=. if reoff`x'month==. 
	gen ihs_numoff`x'=asinh(numberoff`x')
	replace reoffa=reoff`x'month
			}
	save baseline.dta
			
*******************************************************************************			
************************************Table 3************************************
*******************************************************************************
** % any reoffending
		bysort jindex_hd_old: sum reoff*month  
** number of new offences		
		bysort jindex_hd_old: sum  numberoff*

*******************************************************************************			
***********************************Table 4 & Figure 2**************************
*******************************************************************************
	local N=20 
	mat treat=J(`N',1,0) 
	mat lb=J(`N',1,0)
	mat ub=J(`N',1,0)
	mat month=J(`N',1,0)
	
	forvalues x=1/`N' {
	global controlsx " nprior5_courtj nolegrep i.lga  "
.   global controlsa " age age2 gender injury neg_driving break_enter theft fraud pub_order traffic"
    global controlsb "i.courtid#i.year "
  	ivreg2 reoff`x'month $controlsb $controlsa $controlsx  (jindex_hd_old= judge_hd_proc) if   indexapr_flag=="Yes" & year<2008 &  reoff`x'month~=.,  cluster(CourtLocationID mspdi) endog(jindex_hd_old  ) partial($controlsb i.lga )  first sfirst savefirst
	******************************Table 4**************************************
    estimates restore _ivreg2_jindex_hd_old 
	outreg2 using "Table4.xls",  sortvar(judge_hd_proc  judge_ss_proc jindex_hd jindex_ss i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(1stStageAllcontrols) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)
    mat A=e(b)
	local coef=A[1,1]
	mat treat[`x', 1]=`coef'
	matrix v=e(V)
	local sterror=sqrt(v[1,1])
	local df=e(df_m)
	*matrix lb[`x',1]=`coef'-1.64*`sterror'
	*matrix ub[`x',1]=`coef'+1.64*`sterror'
	matrix lb[`x',1]=`coef'-invttail(`df', 0.05)*`sterror'
	matrix ub[`x',1]=`coef'+invttail(`df', 0.05)*`sterror'
	matrix month[`x', 1]=`x'*6
	}
		svmat treat, names(treat_estimates)
	svmat lb, names(lower_bound)
	svmat ub, names(upper_bound)
	svmat month, names(months)
	******************************Figure 2*************************************
	twoway line treat_estimates1 months1, sort lcolor(black) || ///
	line lower_bound1 months1, sort lcolor(black) lpattern(dash)|| ///
	line upper_bound1 months1, sort lcolor(black) lpattern(dash)|| ///
	, yline(0, lstyle(foreground)  lcolor(grey) ) legend(off)ytitle(coefficient) ylabel(-1.0(0.2)0.6, ticks) xtitle(Months after Finalization) xlabel(6(6)120, angle(forty_five) ticks)  saving(reoff, replace)
    graph export "Figure2_Reoffending.pdf", replace

use baseline.dta, clear
local N=20 
	mat treat=J(`N',1,0) 
	mat lb=J(`N',1,0)
	mat ub=J(`N',1,0)
	mat month=J(`N',1,0)
	
	mat recidp=J(`N',1,0) 
	mat recidhd=J(`N',1,0) 
	forvalues x=1/`N' {
	global controlsx " nprior5_courtj nolegrep i.lga  "
.   global controlsa " age age2 gender injury neg_driving break_enter theft fraud pub_order traffic"
    global controlsb "i.courtid#i.year "
    ivreg2 ihs_numoff`x'  $controlsb $controlsa $controlsx  (jindex_hd_old= judge_hd_proc) if   indexapr_flag=="Yes" & year<2008 &  reoff`x'month~=.,  cluster(CourtLocationID mspdi) endog(jindex_hd_old  ) partial($controlsb i.lga )  first sfirst savefirst
	mat A=e(b)
	local coef=A[1,1]
	mat treat[`x', 1]=`coef'
	matrix v=e(V)
	local sterror=sqrt(v[1,1])
	local df=e(df_m)
	*matrix lb[`x',1]=`coef'-1.64*`sterror'
	*matrix ub[`x',1]=`coef'+1.64*`sterror'
	matrix lb[`x',1]=`coef'-invttail(`df', 0.05)*`sterror'
	matrix ub[`x',1]=`coef'+invttail(`df', 0.05)*`sterror'
	matrix month[`x', 1]=`x'*6
	}
	
	svmat treat, names(treat_estimates)
	svmat lb, names(lower_bound)
	svmat ub, names(upper_bound)
	svmat month, names(months)
	******************************Figure 2*************************************
	twoway line treat_estimates1 months1, sort lcolor(black) || ///
	line lower_bound1 months1, sort lcolor(black) lpattern(dash)|| ///
	line upper_bound1 months1, sort lcolor(black) lpattern(dash)|| ///
	, yline(0, lstyle(foreground)  lcolor(grey) ) legend(off)ytitle(coefficient) ylabel(-1.6(0.2)0.8, ticks) xtitle(Months after Finalization) xlabel(6(6)120, angle(forty_five) ticks) saving(NumNewCharges, replace)
    graph export "Figure2_number new offences.pdf", replace

*******************************************************************************
*********************Table 5***************************************************
*******************************************************************************
use baseline.dta, clear
  global controlsx " nprior5_courtj nolegrep i.lga  "
. global controlsa " age age2 gender injury neg_driving break_enter theft fraud pub_order traffic"
  global controlsb "i.courtid#i.year"	
		regress reoff14month $controlsb $controlsa $controlsx  jindex_hd_old judge_hd_proc if   indexapr_flag=="Yes" & year<2008 &  reoff14month~=.,  cluster(CourtLocationID) 
	gen samp14=e(sample)
	gen ihs_numoff14=asinh(numberoff14)
	

 **********************************************Column 1: 0-1.5 years
 ****OLS no controls
 regress reoff3month $controlsb   jindex_hd_old  if  samp14==1&  indexapr_flag=="Yes" & year<2008 &  reoff3month~=.,  cluster(CourtLocationID) 
 outreg2 using "Table5.xls", sortvar(jindex_hd_old i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(2YrsOLSNC) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

 ****OLS small controls
 regress reoff3month $controlsb $controlsa  jindex_hd_old  if samp14==1&   indexapr_flag=="Yes" & year<2008 &  reoff3month~=.,  cluster(CourtLocationID) 
 outreg2 using "Table5.xls", sortvar(jindex_hd_old i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(2YrsOLSSC) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

  ****OLS all controls
 regress reoff3month $controlsb $controlsa $controlsx  jindex_hd_old  if samp14==1&   indexapr_flag=="Yes" & year<2008 &  reoff3month~=.,  cluster(CourtLocationID) 
 outreg2 using "Table5.xls", sortvar(jindex_hd_old i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(2YrsOLSAC) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

   ****Reduced Form all controls
 regress reoff3month $controlsb $controlsa $controlsx  judge_hd_proc  if samp14==1&   indexapr_flag=="Yes" & year<2008 &  reoff3month~=.,  cluster(CourtLocationID) 
 outreg2 using "Table5.xls", sortvar(judge_hd_proc jindex_hd i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(2YrsRF) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

 ***********IV 1.5 yrs
 ivreg2 reoff3month  $controlsb $controlsa $controlsx  (jindex_hd_old= judge_hd_proc) if samp14==1&  indexapr_flag=="Yes" & year<2008 &  reoff3month~=. ,  cluster(CourtLocationID mspdi) endog(jindex_hd_old  ) partial($controlsb i.lga ) 
  outreg2 using "Table5.xls", sortvar(jindex_hd i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(2YrsIV) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

 **********************************************Column 3: 0-84 months
 ****OLS no controls
 regress reoff14month $controlsb   jindex_hd_old  if   indexapr_flag=="Yes" & year<2008 &  reoff14month~=.,  cluster(CourtLocationID) 
 outreg2 using "Table5.xls", sortvar(jindex_hd_old i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(7YrsOLSNC) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

 ****OLS small controls
 regress reoff14month $controlsb $controlsa  jindex_hd_old  if   indexapr_flag=="Yes" & year<2008 &  reoff14month~=.,  cluster(CourtLocationID) 
 outreg2 using "Table5.xls", sortvar(jindex_hd_old i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(7YrsOLSSC) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

  ****OLS all controls
 regress reoff14month $controlsb $controlsa $controlsx  jindex_hd_old  if   indexapr_flag=="Yes" & year<2008 &  reoff14month~=.,  cluster(CourtLocationID) 
 outreg2 using "Table5.xls", sortvar(jindex_hd_old i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(7YrsOLSAC) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

   ****Reduced Form all controls
 regress reoff14month $controlsb $controlsa $controlsx  judge_hd_proc  if   indexapr_flag=="Yes" & year<2008 &  reoff14month~=.,  cluster(CourtLocationID) 
 outreg2 using "Table5.xls", sortvar(judge_hd_proc jindex_hd i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(7YrsRF) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

 ***********IV 7 yrs
  	ivreg2 reoff14month  $controlsb $controlsa $controlsx  (jindex_hd_old= judge_hd_proc) if samp14==1&  indexapr_flag=="Yes" & year<2008 &  reoff14month~=. ,  cluster(CourtLocationID mspdi) endog(jindex_hd_old  ) partial($controlsb i.lga ) 
  outreg2 using "Table5.xls", sortvar(jindex_hd i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(7YrsIV) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

 **********************************************Column 4: number of offenses 0-84 months
 ****OLS no controls
 regress ihs_numoff14  $controlsb   jindex_hd_old  if samp14==1&   indexapr_flag=="Yes" & year<2008 &  numberoff14~=.,  cluster(CourtLocationID) 
 outreg2 using "Table5.xls", sortvar(jindex_hd_old i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(7YrsNoOfOLSNC) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

 ****OLS small controls
 regress ihs_numoff14  $controlsb $controlsa  jindex_hd_old  if samp14==1&   indexapr_flag=="Yes" & year<2008 &  numberoff14~=.,  cluster(CourtLocationID) 
 outreg2 using "Table5.xls", sortvar(jindex_hd_old i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(7YrsNoOfOLSSC) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

  ****OLS all controls
 regress ihs_numoff14  $controlsb $controlsa $controlsx  jindex_hd_old  if  samp14==1&  indexapr_flag=="Yes" & year<2008 &  numberoff14~=.,  cluster(CourtLocationID) 
 outreg2 using "Table5.xls", sortvar(jindex_hd_old i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(7YrsNoOfOLSAC) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

   ****Reduced Form all controls
 regress ihs_numoff14  $controlsb $controlsa $controlsx  judge_hd_proc  if samp14==1&   indexapr_flag=="Yes" & year<2008 &  numberoff14~=.,  cluster(CourtLocationID) 
 outreg2 using "Table5.xls", sortvar(judge_hd_proc jindex_hd i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(7YrsNoOfRF) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

 *******IV number of offenses
  ivreg2 ihs_numoff14 $controlsb $controlsa $controlsx  (jindex_hd_old= judge_hd_proc) if  indexapr_flag=="Yes" & year<2008 &  numberoff14~=. ,  cluster(CourtLocationID mspdi) endog(jindex_hd_old  ) partial($controlsb i.lga ) 
  outreg2 using "Table5.xls", sortvar(jindex_hd i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(7YrsNumOffIV) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

 **********************************************Column 2: 18-84 months**********
use EM_Reoff.dta, clear
  global controlsx " nprior5_courtj nolegrep i.lga  "
. global controlsa " age age2 gender injury neg_driving break_enter theft fraud pub_order traffic"
  global controlsb "i.courtid#i.year"
	local N=20 
	mat treat=J(`N',1,0) 
	mat lb=J(`N',1,0)
	mat ub=J(`N',1,0)
	mat month=J(`N',1,0)
	
	gen  reoffa18=0
	gen  reoff0month=0
	forvalues x=3/`N' {
	gen cc`x'=(cen<`x'*366/2)
    gen dd`x'=(died<`x'*366/2)
	gen died`x' =(dd`x'==1)
	replace died`x'=0 if dod==.
    gen cen`x' =(cc`x'==1)
	gen  reoff`x'month18=((reoffa18+reoff18`x')>=1)
	replace  reoff`x'month18=. if reoffa18==. 
	replace  reoff`x'month18=. if reoff`x'month18==0  & (died`x'==1|cen`x'==1)
	replace reoffa18=reoff`x'month18
		}
	regress reoff14month $controlsb $controlsa $controlsx  jindex_hd_old judge_hd_proc if   indexapr_flag=="Yes" & year<2008 &  reoff14month~=.,  cluster(CourtLocationID) 
	gen samp14=e(sample)	
****OLS no controls
 regress reoff14month18 $controlsb   jindex_hd_old  if   indexapr_flag=="Yes" & year<2008 &  reoff14month18~=.,  cluster(CourtLocationID) 
 outreg2 using "Table5.xls", sortvar(jindex_hd_old i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(7YrsOLSNC) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

 ****OLS small controls
 regress reoff14month18 $controlsb $controlsa  jindex_hd_old  if   indexapr_flag=="Yes" & year<2008 &  reoff14month18~=.,  cluster(CourtLocationID) 
 outreg2 using "Table5.xls", sortvar(jindex_hd_old i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(7YrsOLSSC) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

  ****OLS all controls
 regress reoff14month18 $controlsb $controlsa $controlsx  jindex_hd_old  if   indexapr_flag=="Yes" & year<2008 &  reoff14month18~=.,  cluster(CourtLocationID) 
 outreg2 using "Table5.xls", sortvar(jindex_hd_old i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(7YrsOLSAC) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

   ****Reduced Form all controls
 regress reoff14month18 $controlsb $controlsa $controlsx  judge_hd_proc  if   indexapr_flag=="Yes" & year<2008 &  reoff14month18~=.,  cluster(CourtLocationID) 
 outreg2 using "Table5.xls", sortvar(judge_hd_proc jindex_hd i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(7YrsRF) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

 ********IV
		ivreg2 reoff14month18 $controlsb $controlsa $controlsx  (jindex_hd_old= judge_hd_proc) if samp14==1 & indexapr_flag=="Yes" & year<2008 &  reoff14month18~=. ,  cluster(CourtLocationID mspdi) endog(jindex_hd_old  ) partial($controlsb i.lga ) 
   outreg2 using "Table5.xls", sortvar(jindex_hd i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(2_7Yrs) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)
 
 ******************************************************************************
 ******************************************Table 6: exclusion restriction******
*******************************************************************************
 **Judge sentence length tendency as an additional control
use baseline.dta, clear
  global controlsx " nprior5_courtj nolegrep i.lga  "
. global controlsa " age age2 gender injury neg_driving break_enter theft fraud pub_order traffic"
  global controlsb "i.courtid#i.year"

ivreg2 reoff14month $controlsb $controlsa $controlsx judge_SL_proc (jindex_hd_old= judge_hd_proc) if   indexapr_flag=="Yes" & year<2008 &  reoff14month~=.,  cluster(CourtLocationID mspdi) endog(jindex_hd_old  ) partial($controlsb i.lga )  first sfirst savefirst
      outreg2 using "Table6.xls",  sortvar(judge_hd_proc  judge_ss_proc jindex_hd jindex_ss i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(IVREoff_contolprocSL) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)
estimates restore _ivreg2_jindex_hd_old 
	  outreg2 using "Table6.xls",  sortvar(judge_hd_proc  judge_ss_proc jindex_hd jindex_ss i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(1stStagecontolprocSL) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)
ivreg2 ihs_numoff14 $controlsb $controlsa $controlsx judge_SL_proc (jindex_hd_old= judge_hd_proc) if  indexapr_flag=="Yes" & year<2008 &  numberoff14~=. ,  cluster(CourtLocationID mspdi) endog(jindex_hd_old  ) partial($controlsb i.lga ) 
     outreg2 using "Table6.xls", sortvar(jindex_hd i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(NumOffIVcontolprocSL) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)

 **judge_sentence length tendency as an additional endogenous variable
ivreg2 reoff14month $controlsb $controlsa $controlsx  (jindex_hd_old sentencel = judge_hd_proc judge_SL_proc) if   indexapr_flag=="Yes" & year<2008 &  reoff14month~=.,  cluster(CourtLocationID mspdi) endog(jindex_hd_old  ) partial($controlsb i.lga )  first sfirst savefirst
      outreg2 using "Table6.xls",  sortvar(judge_hd_proc  judge_ss_proc jindex_hd jindex_ss i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(IVBOTHreoff) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)
estimates restore _ivreg2_jindex_hd_old 
	  outreg2 using "Table6.xls",  sortvar(judge_hd_proc  judge_ss_proc jindex_hd jindex_ss i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(1stStageBoth_HD) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)
estimates restore _ivreg2_sentencel 
	  outreg2 using "Table6.xls",  sortvar(judge_hd_proc  judge_ss_proc jindex_hd jindex_ss i.jcrime_type age age2 gender  i.seifa_q $controlsx ) ctitle(1stStageBoth_SL) drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)
ivreg2 ihs_numoff14 $controlsb $controlsa $controlsx  (jindex_hd_old sentencel = judge_hd_proc judge_SL_proc) if   indexapr_flag=="Yes" & year<2008 &  reoff14month~=.,  cluster(CourtLocationID mspdi) endog(jindex_hd_old  ) partial($controlsb i.lga )  first sfirst savefirst
      outreg2 using "Table6.xls",  sortvar(judge_hd_proc  judge_ss_proc jindex_hd jindex_ss i.jcrime_type age age2 gender  i.seifa_q $controlsx )  drop(_Icourtid* _Iyear* _Ilga* i.courtid#i.year i.lga)  excel  label dec(2)


 